package com.it.plic;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author げっしょく
 * @date 2021/8/8
 */
public class Demo9_1 {

    public static void main(String[] args) throws IOException {
        ServerSocket s = new ServerSocket(10000);
        ThreadPoolExecutor te = new ThreadPoolExecutor(
                2,//核心线程数量
                10,//总共线程数量
                10,//休息时间就释放
                TimeUnit.SECONDS,//休息时间的单位
                new ArrayBlockingQueue<>(10),//允许多少排队
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.AbortPolicy()//任务拒绝策略
        );
        while (true) {
            Socket accept = s.accept();
            ThreadD8 td = new ThreadD8(accept);
            te.submit(td);
        }
    }
}
